package com.dupt.system.service.impl;

import com.dupt.common.utils.DictUtils;
import com.dupt.system.domain.AssembleMaterial;
import com.dupt.system.domain.vo.AssembleMaterialVo;
import com.dupt.system.domain.vo.AssemblePlanVo;
import com.dupt.system.mapper.AssembleMaterialMapper;
import com.dupt.system.mapper.AssemblePlanDingTalkMapper;
import com.dupt.system.service.IAssembleDingTalkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;


@Service
public class AssembleDingTalkServiceImpl implements IAssembleDingTalkService {


    @Autowired
    private AssemblePlanDingTalkMapper assemblePlanDingTalkMapper;
    @Autowired
    private AssembleMaterialMapper assembleMaterialMapper;
    @Override
    public List<AssemblePlanVo> selectAssemblePlanListOfDingTalk() {
        //查询所有未组装完成的组装计划
        List<AssemblePlanVo> assemblePlanList = assemblePlanDingTalkMapper.selectAssemblePlanDingTalkList(null);
        //转换词典
        assemblePlanList.forEach(detail -> {
            detail.setApplicableTemp(DictUtils.getDictLabel("sys_applicable_temp",detail.getApplicableTemp()));
            detail.setUnit(DictUtils.getDictLabel("sys_material_unit",detail.getUnit()));
        });
        AssembleMaterial assembleMaterial = new AssembleMaterial();
        for(int i = 0;i<assemblePlanList.size();i++){
            //根据组装计划ID，查询相关用料
            List<AssembleMaterialVo> assembleMaterialList = assembleMaterialMapper.selectAssembleMaterialByAssemblePlanId(assemblePlanList.get(i).getAssembleId());
            assembleMaterialList.forEach(detail -> {
//                detail.setApplicableTemp(DictUtils.getDictLabel("sys_applicable_temp",detail.getApplicableTemp()));
//                detail.setUnit(DictUtils.getDictLabel("sys_material_unit",detail.getUnit()));
                detail.setRequisitionStatus(DictUtils.getDictLabel("sys_requisition_status",detail.getRequisitionStatus()));
            });
            assemblePlanList.get(i).setAssembleMaterialList(assembleMaterialList);
        }
        return assemblePlanList;
    }
}
